package com.yiding.sys.common.enums;

import cn.hutool.core.util.StrUtil;

/**
 * @author War horse imwarhorse@aliyun.com
 * Date: 2020/10/18
 * Description: 订单状态枚举类
 */

public enum OrderStatusEnum {
	UNFINISHED((byte) 0, "未完成"), COMPLETED((byte) 1, "已完成");

	private byte code;
	private String name;

	OrderStatusEnum(byte code, String name) {
		this.code = code;
		this.name = name;
	}

	public static OrderStatusEnum getEnum(String name) {
		if (StrUtil.isEmpty(name)) return null;
		for (OrderStatusEnum value : OrderStatusEnum.values()) {
			if (value.getName().equals(name)) {
				return value;
			}
		}
		return null;
	}

	public static OrderStatusEnum getEnum(byte code) {
		for (OrderStatusEnum value : OrderStatusEnum.values()) {
			if (value.getCode() == code) {
				return value;
			}
		}
		return null;
	}

	public byte getCode() {
		return code;
	}

	public String getName() {
		return name;
	}
}
